#include <iostream>
#include <pthread.h>
#include <unistd.h>
using namespace std;

//转化为十六进制
string toHex(pthread_t tid)
{
    char buffer[64];
    snprintf(buffer,sizeof(buffer),"0x%lx",tid);
    return buffer;
}

void *routine(void* args)
{
    string name = static_cast<const char*>(args);
    while(true)
    {
        cout << "I am new thread,the name is:" << name <<",this thread's id is:" << toHex(pthread_self()) <<endl;
        sleep(1);
        break;
    }
    int *p = new int(10);
    return (void*)p;
}

int main()
{
    pthread_t id1;
    pthread_create(&id1,nullptr,routine,(void*)"thread-1");
    void* ret = nullptr;
    pthread_join(id1,&ret);
    cout<<*(int*)ret<<endl;
    return 0;
}